<?php
// No directAcces
defined('_AppBackMiage') or die('Restricted access');
if(isAdministrateur ()){
    include_once (DS . "backoffice/include/header.php");
    ?>
    <?php
    include_once( DS . "backoffice/include/toppanel_utilisateurs.php");

    $nbrResultPerPage = 10;

    if (isset($_GET['page']) && !empty($_GET['page']))
    {
        $page = $_GET['page'];
        $nbr = (((int) $_GET['page'] - 1) * $nbrResultPerPage);
        $lstEntreprise = Entreprise::getList($nbrResultPerPage, $nbr);
    }
    else
    {
        $page = 1;
        $lstEntreprise = Entreprise::getList($nbrResultPerPage, 0);
    }

    $count = Entreprise::globalCount();
    $pages = ceil($count / $nbrResultPerPage);
    $pageSuivante = $page + 1;
    $pagePrecendente = $page - 1;
    ?>
    <div id="wrapper">
        <div id="content">
            <div id="rightnow">
                <?php
                $title = "Entreprises";
                $add = '<a class="add" href="' . URL . 'index.php?m=admin_useradd_entreprise">Ajouter une entreprise</a>';
                ?>

                <h3 class="reallynow">
                    <span>Liste des <?php echo $title; ?></span>
    <?php echo $add; ?>
                    <br />
                </h3>

                <p class="youhave">
                    <?php

                    if (!empty($lstEntreprise))
                    {
                    ?>
                    <table width="100%">
                        <thead>
                            <tr>
                                <th>Nom</th>
                                <th>Email</th>
                                <th>Ville</th>
                                <th width="60px">Action</th>
                            </tr>
                        </thead>
                        <tbody>
                        <?php
                        foreach ($lstEntreprise as $u)
                        {
                            $viewURL = URL . "/index.php?m=admin_userview_entreprise&uid=" . $u->IdEntreprise;
                            $editURL = URL . "/index.php?m=admin_userentreprise_edit&uid=" . $u->IdEntreprise;
                        ?>
                            <tr>
                                <td><?php echo stripslashes($u->NomEntreprise); ?></td>
                                <td><?php echo $u->MailEntreprise; ?></td>
                                <td><?php echo $u->VilleEntreprise; ?></td>
                                <td>
                                    <a href="<?php echo $viewURL; ?>">
                                        <img src="<?php echo STYLEBK; ?>img/icons/user.png" title="Show profile" width="16" height="16" />
                                    </a>

                                    <a href="<?php echo $editURL; ?>">
                                        <img src="<?php echo STYLEBK; ?>img/icons/user_edit.png" title="Edit user" width="16" height="16" />
                                    </a>
                                </td>
                            </tr>
                        <?php
                        }
                        ?>
                    </tbody>
                </table>
                <div id="pager">
                    Page
    <?php if ($pagePrecendente > 0): ?>
                            <a href="<?php echo URL . "/index.php?m=admin_userentreprise_list&page=" . $pagePrecendente; ?>"><img src="<?php echo STYLEBK; ?>img/icons/arrow_left.gif" width="16" height="16" /></a>
                    <?php endif; ?>
                    <?php echo $page; ?>
    <?php if ($pageSuivante <= $pages): ?>
                                <a href="<?php echo URL . "/index.php?m=admin_userentreprise_list&page=" . $pageSuivante; ?>"><img src="<?php echo STYLEBK; ?>img/icons/arrow_right.gif" width="16" height="16" /></a>
    <?php endif; ?>
                                sur <?php echo $pages; ?> | Total <strong><?php echo $count; ?> </strong> entreprise<?php if ($count > 1)
                                {
                                    echo 's';
                                } ?> trouv&eacute;e<?php if ($count > 1)
                                {
                                    echo 's';
                                } ?>.
                                </div>
    <?php
                            }
                            else
                            {
                                echo 'Aucun r&eacute;sultat';
                            }
    ?>
                                    </p>

                                </div>
                            </div>
    <?php
    include_once (DS . "backoffice/include/sidebar.php");
    include_once (DS . "backoffice/include/footer.php");
}
else
{
    redirectTo(URLBACK);
}
?>